﻿@inherits BaseForm<JxBillHead>

<BillHeadTypeForm Form="Model">
    <AntRow>
        <DataItem Span="6" Label="业务单号" Required>
            <AntInput Disabled @bind-Value="@context.BillNo" />
        </DataItem>
        <DataItem Span="6" Label="单证状态">
            <KTag Text="@context.Status" />
        </DataItem>
        <DataItem Span="6" Label="单证日期" Required>
            <AntDatePicker @bind-Value="@context.BillDate" />
        </DataItem>
        <DataItem Span="6" Label="商业伙伴" Required>
            <PartnerPicker Value="@context.Partner" AllowClear Type="@GetPartnerPickerType(context)"
                           ValueChanged="e=>context.Partner=e?.ToString()" />
        </DataItem>
    </AntRow>
    <AntRow>
        <DataItem Span="6" Label="合同号">
            <AntInput @bind-Value="@context.ContractNo" />
        </DataItem>
        <DataItem Span="6" Label="发票号">
            <AntInput @bind-Value="@context.InvoiceNo" />
        </DataItem>
        <DataItem Span="6" Label="结算方式" Required>
            <AntSelectCode @bind-Value="@context.SettleMode" Category="@DicCategory.SettleMode" />
        </DataItem>
        <DataItem Span="6" Label="总金额">
            <AntDecimal Disabled @bind-Value="@context.TotalAmount" /> 元
        </DataItem>
    </AntRow>
    <AntRow>
        <DataItem Span="6" Label="物流公司">
            <AntInput @bind-Value="@context.Logistics" />
        </DataItem>
        <DataItem Span="6" Label="物流单号">
            <AntInput @bind-Value="@context.LogisticsNo" />
        </DataItem>
        <DataItem Span="6" Label="物流费用">
            <AntDecimal @bind-Value="@context.LogisticsFee" /> 元
        </DataItem>
        @if (context.Type == BillType.ImportReturn || context.Type == BillType.ExportReturn)
        {
            <DataItem Span="6" Label="被退单号">
                <AntInput Disabled @bind-Value="@context.ReturnNo" />
            </DataItem>
        }
    </AntRow>
    <AntRow>
        <DataItem Span="12" Label="备注">
            <AntTextArea @bind-Value="@context.Note" />
        </DataItem>
        <DataItem Span="12" Label="附件">
            <KUpload @ref="upload" ReadOnly="Model.IsView" Value="@context.Files"
                     IsButton="!Model.Data.IsNew" OnFilesChanged="OnFilesChangedAsync" />
        </DataItem>
    </AntRow>
</BillHeadTypeForm>

<div class="kui-toolbar">
    <KTitle Text="商品明细" />
    <div>
        @if (!Model.IsView)
        {
            <Button Type="@ButtonType.Primary" Icon="plus" OnClick="OnAdd">添加</Button>
        }
    </div>
</div>
<BillListTypeTable DataSource="Model.Data.Lists" HidePagination ScrollX="1300px" ScrollY="200px">
    <IntegerColumn Title="序号" Field="@context.SeqNo" Width="60" Fixed="left" />
    <StringColumn Title="商品名称" Field="@context.Name" Width="120" Fixed="left">
        @if (Model.IsView)
        {
            @context.Name
        }
        else
        {
            <AntSelectCode @bind-Value="@context.Code" DataSource="GoodsCodes" OnSelectedItemChanged="e=>OnGoodsChange(e,context)" />
        }
    </StringColumn>
    <StringColumn Title="商品类别" Field="@context.Category" Width="100" />
    <StringColumn Title="规格型号" Field="@context.Model" Width="150" />
    <StringColumn Title="产地" Field="@context.Producer" Width="100" />
    <StringColumn Title="计量单位" Field="@context.Unit" Width="100" />
    <StringColumn Title="数量" Width="100">
        @if (Model.IsView)
        {
            @context.Qty
        }
        else
        {
            <AntInteger @bind-Value="@context.Qty" OnChange="e=>OnGoodsChange(1, context)" />
        }
    </StringColumn>
    <StringColumn Title="单价" Width="100">
        @if (Model.IsView)
        {
            @context.Price
        }
        else
        {
            <AntDecimal @bind-Value="@context.Price" OnChange="e=>OnGoodsChange(2, context)" />
        }
    </StringColumn>
    <StringColumn Title="金额" Width="100">
        @if (Model.IsView)
        {
            @context.Amount
        }
        else
        {
            <AntDecimal @bind-Value="@context.Amount" OnChange="e=>OnGoodsChange(3, context)" />
        }
    </StringColumn>
    <StringColumn Title="备注" Width="100">
        @if (Model.IsView)
        {
            @context.Note
        }
        else
        {
            <AntInput @bind-Value="@context.Note" />
        }
    </StringColumn>
    @if (!Model.IsView)
    {
        <ActionColumn Title="操作" Align="ColumnAlign.Center" Width="100" Fixed="right">
            <Tag Color="red-inverse" OnClick="e=>OnDelete(context)">删除</Tag>
        </ActionColumn>
    }
    <SummaryRow>
        <SummaryCell Fixed="left">合计</SummaryCell>
        <SummaryCell Fixed="left" />
        <SummaryCell />
        <SummaryCell />
        <SummaryCell />
        <SummaryCell />
        <SummaryCell>@Model.Data.Lists.Sum(l => l.Qty)</SummaryCell>
        <SummaryCell />
        <SummaryCell>@Model.Data.Lists.Sum(l => l.Amount)</SummaryCell>
        <SummaryCell />
        @if (!Model.IsView)
        {
            <SummaryCell />
        }
    </SummaryRow>
</BillListTypeTable>